package com.lineage.server.serverpackets;

import com.lineage.config.ConfigOther;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Character;
import com.lineage.server.model.L1Object;
import com.lineage.server.world.World;

public class S_AttackPacketNpc extends ServerBasePacket {
  private byte[] _byte;
  
  public S_AttackPacketNpc(L1NpcInstance npc, L1Character target, int actid, int dmg) {
    this._byte = null;
    writeC(30);
    writeC(actid);
    writeD(npc.getId());
    int targetobj = target.getId();
    L1Object obj = World.get().findObject(targetobj);
    if (obj instanceof L1NpcInstance) {
      L1NpcInstance tgnpc = (L1NpcInstance)obj;
      int[] bow_GFX_Arrow = ConfigOther.AtkNo;
      int array[], n = (array = bow_GFX_Arrow).length;
      int i = 0;
      while (i < n) {
        int gfx = array[i];
        if (tgnpc.getTempCharGfx() == gfx)
          targetobj = 0; 
        i++;
      } 
      switch (tgnpc.getTempCharGfx()) {
        case 2544:
        case 10913:
          targetobj = 0;
          break;
      } 
    } 
    if (obj instanceof L1PcInstance) {
      L1PcInstance pc = (L1PcInstance)obj;
      int[] atkpc = ConfigOther.AtkNo_pc;
      int array[], n = (array = atkpc).length;
      int i = 0;
      while (i < n) {
        int gfx = array[i];
        if (pc.getTempCharGfx() == gfx)
          targetobj = 0; 
        i++;
      } 
    } 
    writeD(targetobj);
    if (target instanceof L1PcInstance) {
      L1PcInstance tg = (L1PcInstance)target;
      if (tg.getTempCharGfx() == 23353 || tg.getTempCharGfx() == 23759)
        dmg = 0; 
    } 
    if (dmg > 0) {
      writeH(10);
    } else {
      writeH(0);
    } 
    writeC(npc.getHeading());
    writeH(0);
    writeH(0);
    writeC(0);
  }
  
  public S_AttackPacketNpc(L1NpcInstance npc, L1Character target, int actid) {
    this._byte = null;
    writeC(30);
    writeC(actid);
    writeD(npc.getId());
    writeD(target.getId());
    writeH(0);
    writeC(npc.getHeading());
    writeH(0);
    writeH(0);
    writeC(0);
  }
  
  public byte[] getContent() {
    if (this._byte == null)
      this._byte = getBytes(); 
    return this._byte;
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
